import 'package:eplorex/dao/activity_details_dao.dart';
import 'package:eplorex/models/activity/activity_types.dart' as actvitymodel;
import 'package:eplorex/pages/activity/activity_item.dart';
import 'package:eplorex/widgets/filterbar/filterbar.dart';
import 'package:flutter/material.dart';

class ActivityTabListPage extends StatefulWidget {
  const ActivityTabListPage({super.key});

  @override
  State<ActivityTabListPage> createState() => _ActivityTabListPageState();
}

class _ActivityTabListPageState extends State<ActivityTabListPage> {
  Future<List<actvitymodel.ActivityItem>>? _activityItem;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    _activityItem = ActivityDetailsDao.fetchActivityItems();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        FilterBar(
          onChange: (data) {},
        ),
        SizedBox(
          height: 10,
        ),
        _getListView()
      ],
    );
  }

  Widget _getListView() {
    return Expanded(
      child: FutureBuilder(
        future: _activityItem,
        builder: (BuildContext context,
            AsyncSnapshot<List<actvitymodel.ActivityItem>> snapshot) {
          if (snapshot.connectionState == ConnectionState.waiting) {
            return Center(
                child: Text(
              "loadin...",
            ));
          }
          return ListView.builder(
            itemCount: snapshot.data!.length,
            itemBuilder: (BuildContext context, int index) {
              return ActivityItem(snapshot.data![index]);
            },
          );
        },
      ),
    );
  }
}
